home *** CD-ROM | disk | FTP | other *** search
- Path: news.smartt.com!usenet
- From: kparkin@smartt.com (The REFEREE)
- Newsgroups: comp.lang.c++
- Subject: Re: HELP !! Please !! Read Me !!!!
- Date: Tue, 26 Mar 1996 04:42:58 GMT
- Organization: Student@BCIT
- Message-ID: <4j7s8m$k3p@ktk2.smartt.com>
- References: <4j7prk$j0h@ktk2.smartt.com>
- NNTP-Posting-Host: burn-m085.smartt.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi.....
-
- I forgot to add one more file to my last entry into this newsgroup to
- add to my current program.
-
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- For assignment 1, rather than using CĂs stream IO library (fopen,
- fread, fclose) for the input file, you may want or prefer to use a
- C++ iostream object. As mentioned before, there are three pre-defined
- iostream objects:
- â cout
- â cin
- â cerr
-
- You can create a user defined iostream object as follows:
-
-
- // program to count words in a user specified file
- #include <iostream.h>
- #include <iomanip.h>
- #include <fstream.h>
- #include <stdlib.h>
- int main ()
- {
- ifstream myStream; // create input iostream object,
- // can be used like cin.
- char inbuff[80];
- char filename[80];
- int wc=0;
-
- // prompt the user for a file name to open
- cout << "Enter a file name: ";
- cin >> setw(80) >> filename;
-
- // open the file and associate it with the iostream object, defaults
- to input.
- myStream.open(filename);
- if (!myStream)
- {
- cout << "Error openning file" << filename << endl;
- exit(1);
- }
-
- // read and count words in file
- while (myStream >> inbuff)
- wc++;
-
- myStream.close();
-
- cout << "The number of words in file " << filename << "is " << wc;
- return 0;
- }
-
- +++++++++++++++++++++++++++++++++++++++++++++++++++++=
-
-
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- It takes a big man to cry, but it takes a
- bigger man to laugh at that man. -- Jack Handy
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
-
- Ken Parkin ( REFEREE on mIRC )
-
- E-mail #1 : kparkin@smartt.com
- E-mail #2 : g1140066@bcit.bc.ca
- HmPg #1 : http://www.studentaccess.com/hp/REFEREE/
- HmPg #2 : http://www.soe.bcit.bc.ca/scas/cst/year1/setg/ken/
-
- Go Flames Go !!!!!
-
-